from rest_framework import serializers
from .models import Leave


class LeaveSerializer(serializers.ModelSerializer):

    class Meta:
        model = Leave
        fields = ['id', 'name', 'mobile', 'gender', 'data_birth', 'department_name', 'department_type', 'job',
                  'leave_category', 'leave_reason', 'leave_time', 'start_time', 'leave_days', 'leave_type',
                  'leave_type_name']

    leave_type_name = serializers.SerializerMethodField(read_only=True)

    def get_leave_type_name(self, obj):
        return obj.get_leave_type_display()